//
//  GBCollectViewController.m
//  警用舆情平台
//
//  Created by 郭斌 on 15/5/13.
//  Copyright (c) 2015年 魏强. All rights reserved.
//

#import "GBCollectViewController.h"
#import "GBTableView.h"
#import "GBSingleWebViewController.h"
#import "GBModel.h"
#define baseUrl @"method=listFavorite&token="
#define p @"&p=1&limit=10"

@interface GBCollectViewController ()
{
    NSString *collectUrl; //收藏列表的url
    // 2016/3/15
    UIButton *backButton;
}
@end

@implementation GBCollectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的收藏";
    self.navigationController.navigationBar.barStyle = UIStatusBarStyleDefault;
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    self.view.backgroundColor = [UIColor whiteColor];
    
    backButton = [UIButton buttonWithType:0];
    backButton.frame = CGRectMake(0, 0, 30, 30);
    [backButton setImage:[UIImage imageNamed:@"leftArrow"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backTheView)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

    //初始化收藏列表的url
    [self createCollectUrl];
    //初始化tableview
    [self createTableView];
    //NSLog(@"12");
    //跳转单个界面的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToTheSingleP:) name:@"goToTheSingleView" object:nil];
    
    // Do any additional setup after loading the view.
}

#pragma mark - 返回主界面
-(void)backTheView
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - 跳转到单个界面
-(void)goToTheSingleP:(NSNotification *)note
{
    NSDictionary *user = [note userInfo];
    GBSingleWebViewController *single = [[GBSingleWebViewController alloc] init];
    GBModel *model = user[@"GBModel"];
    single.url = model.url;
    single.titleee = model.title;
    single.docid = model.docId;
    single.keyword = [NSString stringWithFormat:@"%d",model.u_id];
    single.isCollect = 1;
    single.whichPage =  model.whichPage;
    single.favid = [NSString stringWithFormat:@"%d",model.fav_id];
    single.ori_content = model.content;
    single.ori_author = model.author;
    single.ori_webname = model.sourceName;
    single.report = model.report;
    single.comeFrom = @"6";
    NSDateFormatter *_fmt = [[NSDateFormatter alloc]init];
    _fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];;
    _fmt.dateFormat = @"yyyy/MM/dd HH:mm";
    
    single.st = [_fmt stringFromDate:[NSDate dateWithTimeIntervalSince1970:model.fav_time/1000.0]];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:backItem];
    //NSLog(@"%@",single.whichPage);
    single.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:single animated:YES];
    single.hidesBottomBarWhenPushed = NO;
}

#pragma mark - 初始化收藏列表的url
-(void)createCollectUrl
{
    KDAccount *account = [KDAccountTool account];
    //NSLog(@"%@", account.token);
    collectUrl = [NSString stringWithFormat:@"%@&%@%@%@", ServerActionAddr, baseUrl,account.token,p];
    //NSLog(@"%@",collectUrl);
}

#pragma mark - 初始化tableview
-(void)createTableView
{
    //设置tableview2
    GBTableView *tableview = [[GBTableView alloc] initWithFrame:CGRectMake(0, 0, screenW,screenH)];
    tableview.Jurl = collectUrl;
    [self.view addSubview:tableview];
}

#pragma mark - 页面即将出现时
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.hidesBottomBarWhenPushed = YES;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end